package com.cm.caseManagement.controller;

import com.cm.caseManagement.annotation.Log;
import com.cm.caseManagement.core.controller.BaseController;
import com.cm.caseManagement.core.domain.AjaxResult;
import com.cm.caseManagement.core.page.TableDataInfo;
import com.cm.caseManagement.pojo.entity.CmTaskAssign;
import com.cm.caseManagement.pojo.enums.BusinessType;
import com.cm.caseManagement.service.ICmTaskAssignService;
import com.cm.caseManagement.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 任务分配Controller
 *
 * @author ruoyi
 * @date 2025-10-05
 */
@RestController
@RequestMapping("/caseManagement/taskAssign")
public class CmTaskAssignController extends BaseController
{
    @Autowired
    private ICmTaskAssignService cmTaskAssignService;

    /**
     * 查询任务分配列表
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:assign:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmTaskAssign cmTaskAssign)
    {
        startPage();
        List<CmTaskAssign> list = cmTaskAssignService.selectCmTaskAssignList(cmTaskAssign);
        return getDataTable(list);
    }

    /**
     * 导出任务分配列表
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:assign:export')")
    @Log(title = "任务分配", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmTaskAssign cmTaskAssign)
    {
        List<CmTaskAssign> list = cmTaskAssignService.selectCmTaskAssignList(cmTaskAssign);
        ExcelUtil<CmTaskAssign> util = new ExcelUtil<CmTaskAssign>(CmTaskAssign.class);
        util.exportExcel(response, list, "任务分配数据");
    }

    /**
     * 获取任务分配详细信息
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:assign:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cmTaskAssignService.selectCmTaskAssignById(id));
    }

    /**
     * 新增任务分配
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:assign:add')")
    @Log(title = "任务分配", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody CmTaskAssign cmTaskAssign)
    {
        return toAjax(cmTaskAssignService.insertCmTaskAssign(cmTaskAssign));
    }

    /**
     * 修改任务分配
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:assign:edit')")
    @Log(title = "任务分配", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody CmTaskAssign cmTaskAssign)
    {
        return toAjax(cmTaskAssignService.updateCmTaskAssign(cmTaskAssign));
    }

    /**
     * 删除任务分配
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:assign:remove')")
    @Log(title = "任务分配", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmTaskAssignService.deleteCmTaskAssignByIds(ids));
    }
}
